package com.lemon.smartsafetynew.ui.activity.hidden;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafety.utils.common.StringUtils;
import com.lemon.smartsafetynew.entity.event.common.ViewEvent;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenBo;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenDownloadVo;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.lemon.smartsafetynew.util.user.AccountUtil;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by Andrew on 2017/11/1.
 */

public class SafeHiddenDocumentActivity extends SwipeBackActivity {

    @Bind(R.id.site_inspection)
    RelativeLayout siteInspection;
    @Bind(R.id.order_rectification)
    RelativeLayout orderRectification;
    @Bind(R.id.rectification_review)
    RelativeLayout rectificationReview;

    private static SafeHiddenDownloadVo safeHiddenDownloadVo;


    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_SAFE_HIDDEN_DOWNLOAD_VO)) {
                safeHiddenDownloadVo = (SafeHiddenDownloadVo) bundle.getSerializable(KeyConstants.KEY_SAFE_HIDDEN_DOWNLOAD_VO);
            }
        }

    }

    @Override
    protected void initTitle() {
        this.setBarTitle("新建文书");
    }

    @Override
    protected void callFinish() {
        AppService.getBus().post(new ViewEvent(SafeHiddenDocumentActivity.class.getName()));
        AppManager.getAppManager().finishActivity(SafeHiddenDocumentActivity.this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_safe_hidden_document;
    }


    @OnClick({R.id.create_attachment_doc_one, R.id.add_attachment_doc_one, R.id.create_attachment_doc_two, R.id.add_attachment_doc_two, R.id.create_attachment_doc_three, R.id.add_attachment_doc_three})
    public void onViewClicked(View view) {

        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_SAFE_HIDDEN_DOWNLOAD_VO, safeHiddenDownloadVo);

        switch (view.getId()) {
            case R.id.create_attachment_doc_one:
                bundle.putString(KeyConstants.KEY_DOC_TYPE, SafeHiddenBo.Doc.site_inspection_doc.getValue());
                UIHelper.showActivity(SafeHiddenDocumentActivity.this, bundle, SafeHiddenGenerateDocumentActivity.class);
                break;
            case R.id.create_attachment_doc_two:
                bundle.putString(KeyConstants.KEY_DOC_TYPE, SafeHiddenBo.Doc.order_rectification_doc.getValue());
                UIHelper.showActivity(SafeHiddenDocumentActivity.this, bundle, SafeHiddenGenerateDocumentActivity.class);
                break;
            case R.id.create_attachment_doc_three:
                bundle.putString(KeyConstants.KEY_DOC_TYPE, SafeHiddenBo.Doc.rectification_review_doc.getValue());
                UIHelper.showActivity(SafeHiddenDocumentActivity.this, bundle, SafeHiddenGenerateDocumentActivity.class);
                break;
        }

    }

    @Override
    protected void initViews() {
        super.initViews();

        initCommonView();
    }

    private void initCommonView() {

        if (StringUtils.isEmpty(AccountUtil.getTypeId()) || "null".equalsIgnoreCase(AccountUtil.getTypeId())) {
            /**
             * 政府人员没有执法证书，无法开下面两份文书，所以隐藏
             */
            orderRectification.setVisibility(View.GONE);
            rectificationReview.setVisibility(View.GONE);
        } else {
            orderRectification.setVisibility(View.VISIBLE);
            rectificationReview.setVisibility(View.VISIBLE);
        }
    }

}
